-- snowball_damage
-- create by shuzy
-- 道具：雪球伤害，对指定目标怪物造成指定伤害，且掉落物品

return {
    apply = function(source, target, classId, value)
        -- 对特定的怪物伤害有加成
        local damage;
        local baseClassId = target:query("base_class_id");

        if table.indexOf(value[1], baseClassId) == -1 then
            damage = value[2];
        else
            damage = value[3];
        end

        -- 计算最终伤害
        damage = PropertyM.calcFinalDamage(source, target, classId, damage);

        -- 固定伤害
        -- 传入攻击者信息
        local assailantInfo = {
                ["property_id"] = classId,
        };

        if ItemM.query(classId, "apply") == "damage_and_drop" then
            -- 会掉落道具
            CombatM.doDamage(source, target, damage, 0, true, { assailantInfo = assailantInfo, });
        else
            CombatM.doDamage(source, target, damage, 0, false, { assailantInfo = assailantInfo, });
        end

        if table.indexOf(value[1], baseClassId) ~= -1 then
            local dbase = target:query("dbase");
            local toElement = dbase["snowball_damage_summon_element"];
            if type(toElement) == "number" then
                -- 找个空位
                local pos = target:getPos();
                pos = SummonM.findSummonPos(pos);

                if pos > 0 then
                    local toClass = DungeonM.queryElement(toElement, "class");
                    local para = { ["class"] = toClass, ["element"] = toElement };
                    DungeonM.transformGrid(toClass, pos, GRID_STATE_OPEN, para);
                end
            end
        end

        -- 抛出使用道具攻击事件
        EventMgr.fire(event.PROPERTY_ATTACK, { ["classId"] = classId, ["target"] = target, });
    end,
};
